package org.dk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.dk.mapper.TbGoodsMapper;
import org.dk.pageInfo.PageInfo2;
import org.dk.pojo.TbGoods;
import org.dk.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private TbGoodsMapper tbGoodsMapper;
    @Override
    public Long addGoods(TbGoods goods) {
        tbGoodsMapper.addGoods(goods);
        return goods.getId();
    }

    @Override
    public TbGoods selectGoods(Long id) {
        return tbGoodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo2<TbGoods> selectBrand(String goodsName,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbGoods> tbGoods = tbGoodsMapper.selectGoods(goodsName);
        PageInfo<TbGoods> pageInfo = new PageInfo<>(tbGoods);
        PageInfo2<TbGoods> pageInfo1 = new PageInfo2();
        pageInfo1.setPageNum(pageInfo.getPageNum());
        pageInfo1.setPageSize(pageInfo.getSize());
        pageInfo1.setTotal(pageInfo.getTotal());
        pageInfo1.setList(pageInfo.getList());
        pageInfo1.setLastPage(pageInfo.getPages());
        return pageInfo1;
    }

    @Override
    public void deleteGoods(Long[] ids) {
        tbGoodsMapper.deleteGoods(ids);
    }

    @Override
    public void updateGoods(Long[] ids, String auditStatus) {
        tbGoodsMapper.updateGoods(ids,auditStatus);
    }
}
